﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Data;

namespace HQWeb.SysManage.DictionaryManage
{
    public partial class TreeList : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            VerdictIsLogin();
            TreeNode node = new TreeNode();
            node.Value = "0";
            node.Text = "数据字典";
            node.NavigateUrl = "DictionaryManage.aspx";
            node.Target = "mainFrame";
            node.Expanded = true;
            node.SelectAction = TreeNodeSelectAction.SelectExpand;
            this.InitTree(node.ChildNodes, "0");
            this.LeftTree.Nodes.Add(node);
        }

        protected void InitTree(TreeNodeCollection Nds, string parentId)//用递归方法动态生成节点
        {
            BLL.SysManage.T_PUB_DICTIONARY bll = new BLL.SysManage.T_PUB_DICTIONARY();
            DataView dv = new DataView();
            dv.Table = bll.GetList().Tables[0];

            if (parentId == "")
            {
                dv.RowFilter = "PARENT_ID is Null";
            }
            else
            {
                dv.RowFilter = "PARENT_ID=" + "'" + parentId + "'";
            }

            foreach (DataRowView item in dv)
            {
                TreeNode node = new TreeNode();
                node.Value = item["ID"].ToString();
                node.Text = item["NAME"].ToString();
                node.NavigateUrl = "DictionaryManage.aspx?ID=" + item["ID"].ToString();

                node.Target = "mainFrame";
                node.Expanded = false;
                node.SelectAction = TreeNodeSelectAction.SelectExpand;
                Nds.Add(node);
                this.InitTree(node.ChildNodes, node.Value);
            }
        }

        //#region 字典类型数
        //private void InitTree()
        //{
        //    TreeNode node = new TreeNode();
        //    node.Text = "数据字典";
        //    node.Value = "0";
        //    node.Target = "mianFrame";
        //    node.Expanded = true;
        //    node.SelectAction = TreeNodeSelectAction.Expand;
        //    node.NavigateUrl = "DictionaryAddChild.aspx?pid=all";
        //    IList TreeList = new ArrayList();
        //    BLL.SysManage.T_PUB_DICTIONARY bll = new BLL.SysManage.T_PUB_DICTIONARY();
        //    TreeList = bll.GetModelList("FLAG='1'");
        //    AddReplies(node, TreeList);
        //    LeftTree.Nodes.Add(node);
        //}
        //#endregion

        //#region 加载数据字典子节点
        //private void AddReplies(TreeNode node, IList TreeList)
        //{
        //    try
        //    {
        //        string strPid = node.Value;
        //        foreach (Model.SysManage.T_PUB_DICTIONARY item in TreeList)
        //        {
        //            if (item.PARENT_ID.ToString() == strPid)
        //            {
        //                TreeNode repalNode = new TreeNode();
        //                repalNode.Text = item.NAME.Trim();
        //                repalNode.Value = item.ID.ToString();
        //                repalNode.NavigateUrl = "DictionaryAddChild.aspx?pid=" + repalNode.Value;
        //                repalNode.Target = "mainFrame";
        //                repalNode.Expanded = false;
        //                repalNode.SelectAction = TreeNodeSelectAction.Expand;
        //                AddReplies(repalNode, TreeList);
        //            }
        //        }
        //    }
        //    catch (Exception ex)
        //    {

        //        throw new Exception(ex.Message);
        //    }
        //}
        //#endregion

    }
}